import React, { Component } from 'react';
import { StyleSheet, View, Text, Image, Animated, TouchableOpacity, Alert, FlatList } from 'react-native';
import { NavigationEvents } from 'react-navigation';
import navigationSeevice from '../../../../../components/navigation/navigationSeevice';
import { GLOBAL } from '../../../../../config/global';
import { style } from '../../../../../theme/style';
import ToastUtil from '../../../../../utils/toast';
import HTTP from '../../../../../utils/http';
import { API, API_GENERATE } from '../../../../../config/api';
import { orderStyle, commonStyle } from '../../details/_common/style';

let titleImgObj = require('../../../../../imgs/global/down.png');

const scale = GLOBAL.SCALE;
export class GoodsBockCpt extends Component {
	constructor(props) {
		super(props);
		let { visible } = props.data || {};
		this.state = {
			visible,
			modalVisible: false
		}
	}
	_changeFn = () => {
		let { baseData } = this.props;
		let { goodsTreeList } = baseData || [];
		let reselt = false;
		try {
			goodsTreeList.forEach((item, index) => {
				item.goodsList && item.goodsList.forEach((items, indexs) => {
					if (items.operateType === 'C' || items.operateType === 'U' || items.operateType === 'D') {
						reselt = true;
						throw new Error();
					}
				})
			})
		} catch (e) {
			console.log(e)
		}
		return reselt;
	}
	render () {
		let { data, titleStyle, onTitlePress, baseData, onBockPress } = this.props || {};
		let { title } = data || {};
		return (
			<View style={orderStyle.block}>
				<TouchableOpacity activeOpacity={1} onPress={() => { onBockPress && onBockPress() }} style={[orderStyle.blockHead, commonStyle.row2]}>
					<View style={{ flexDirection: 'row', alignItems: 'center' }}>
						<Text style={[commonStyle.fontTitle, titleStyle]}>{title}</Text>
						{this._changeFn() ? <Text style={styles.changeText}>(变更)</Text> : null}
					</View>
					<View style={styles.imgBox}>
						<Animated.Image style={[styles.imgStyle]} source={titleImgObj}></Animated.Image>
					</View>
				</TouchableOpacity>
			</View>
		)
	}
}

const styles = StyleSheet.create({
	imgBox: {
		paddingTop: 5 * scale,
		paddingBottom: 5 * scale,
		paddingLeft: 5 * scale,
		paddingRight: 5 * scale
	},
	imgStyle: {
		tintColor: '#D8D8D8',
		width: 10 * scale,
		height: 6 * scale,
		transform: [{ 'rotate': '-90deg' }],
	},
	body: {
		paddingTop: 10 * scale,
		paddingBottom: 10 * scale,
	},
	bockCptTitleStyle: {
		fontSize: 12 * scale
	},
	addText: {
		color: style.color.themeColor,
		fontSize: 12 * scale,
		marginLeft: 12 * scale
	},
	changeText: {
		color: style.color.fontRed1,
		fontSize: 12 * scale,
		paddingLeft: 5 * scale
	}

})